<?php
/**
 * wvcrAdmin - Admin Section for WordPress Vampire plugins
 * 
 * @author WordPress Vampire
 * @copyright 2011
 * @since 1.0
 */

class wvcrAdmin{
	
	// constructor
	function wvcrAdmin() {
		global $wvcr;

        // Add the script and style files
        add_action('admin_print_scripts', array(&$this, 'load_scripts'));
        add_action('admin_print_styles', array(&$this, 'load_styles') );

		// Add the admin menu
		add_action('admin_menu', array(&$this, 'add_menu'));
	}
	
	function add_menu()  {
		add_submenu_page('edit.php?post_type=coupon', __('Options'), __('Options'), 'edit_posts', 'coupon-options', array(&$this, 'show_menu'));
	}
	
	// load the script for the defined page and load only this code	
	function show_menu() {
 		global $current_screen;

		switch ($current_screen->id) {
			case 'coupon_page_coupon-options':
                require_once(dirname(__FILE__) . '/options.php');
				break;
			default:
				# code...
				break;
		}
	}
	
	function load_scripts() {
		global $current_screen;
			
		wp_enqueue_script('jquery');

		switch ($current_screen->id) {
			case 'coupon':
                wp_enqueue_script('jqueryui', WV_URLPATH . 'admin/js/jquery-ui-1.8.13.custom.min.js', array('jquery'));
                wp_enqueue_script('wvcoupon', WV_URLPATH . 'admin/js/wv.js', array('jquery', 'jqueryui'));

                wp_localize_script('wvcoupon', 'wvSettings', array('url' => WV_URLPATH, 'id' => get_the_ID()));
				break;
			case 'coupon_page_coupon-options':
				wp_enqueue_script('jquery.colorpicker', WV_URLPATH . 'admin/js/colorpicker.js', array('jquery'));
				break;
			default:
				# code...
				break;
		}
		
	}
	
	function load_styles() {
		global $current_screen;
		
		wp_enqueue_style('wvglobal', WV_URLPATH . 'admin/css/global.css' );
		wp_enqueue_style('wvcoupon', WV_URLPATH . 'css/wv.css' );
		
		switch ($current_screen->id) {
			case 'coupon':
                wp_enqueue_style('jqueryui', WV_URLPATH . 'admin/css/jquery-ui-1.8.13.custom.css');
				wp_enqueue_style('edit-coupon', WV_URLPATH . 'admin/css/coupon.css');
				break;
			case 'coupon_page_coupon-options':
				wp_enqueue_style('jquery.colorpicker', WV_URLPATH . 'admin/css/colorpicker.css');
				break;
			default:
				# code...
				break;
		}
	}
	
}

global $wvcr;
$wvcr->acp = new wvcrAdmin();